﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tsgl
{
    public partial class penaltyStay : Form
    {
        public penaltyStay()
        {
            InitializeComponent();
        }

        private string penaltyOperator, borrowerId;

        private void penaltyStay_Load(object sender, EventArgs e)
        {
            cboPenaltyWay.Items.Add("交现款");
            cboPenaltyWay.Items.Add("从押金中扣除");
            cboPenaltyWay.SelectedIndex = 0;
        }

        private void getPenaltyStayInfo()
        {
            DataTable dt = penaltyStayClass.getPenaltyStay(borrowerId) ;
            DataTable dtBorrower=loanClass.getBorrowerInfo(borrowerId);
            if (this.dataGridView1.Rows.Count != 0)
            {
                dataGridView1.DataSource = dt.DefaultView;
                this.txtBorrowerName.DataBindings.Clear();
                this.txtBorrowerName.DataBindings.Add("text", dt.DefaultView, "借阅者姓名");
                this.txtBookCode.DataBindings.Clear();
                this.txtBookCode.DataBindings.Add("text", dt.DefaultView, "图书条码");
                this.txtBookName.DataBindings.Clear();
                this.txtBookName.DataBindings.Add("text", dt.DefaultView, "图书名称");
                this.txtPenaltyReason.DataBindings.Clear();
                this.txtPenaltyReason.DataBindings.Add("text", dt.DefaultView, "罚款原因");
                this.txtPenaltyMoney.DataBindings.Clear();
                this.txtPenaltyMoney.DataBindings.Add("text", dt.DefaultView, "罚款金额");
                if (dtBorrower.Rows.Count != 0)
                {
                    txtForegift.Text = dtBorrower.Rows[0]["押金剩余"].ToString();
                }
            }
            else
            {
                txtBorrowerName.Text = dtBorrower.Rows[0]["姓名"].ToString();
            }

        }

        private void txtBorrowerId_KeyDown(object sender, KeyEventArgs e)
        {
        }

        private void btnSelectBorrowerId_Click(object sender, EventArgs e)
        {
            selectBorrower frm = new selectBorrower();
            frm.ShowDialog();
            borrowerId = frm.getBorrowerId();
            this.txtBorrowerId.Text = borrowerId;
            getPenaltyStayInfo();
        }

        private void btnPenaltyStay_Click(object sender, EventArgs e)
        {
            selectPenalty frm = new selectPenalty();
            frm.ShowDialog();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

    }
}